package koction.controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


import koction.model.product.ProductService;
import koction.model.product.ProductVO;
import koction.model.reviewBoard.ListVO;
import koction.model.reviewBoard.ReviewBoardService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ProductController {
	@Resource(name="productServiceImpl")
	private ProductService productService;
	
	@Resource(name="reviewBoardServiceImpl")
	private ReviewBoardService reviewBoardService;
	
	@RequestMapping("/getProductListByCategory.do")
	public ModelAndView getProductListByCategory(String category){
		List<ProductVO> list=productService.getProductListByCategory(category);
		System.out.println(list);
		ModelAndView mv=new ModelAndView("searchProductList.product","list",list);
		mv.addObject("category",category);
		return mv;
	}
	
	@RequestMapping("/searchProductListByName.do")
	public ModelAndView searchProductListByName(String name, String category){
		List<ProductVO> list=productService.searchProductListByName(name,category);		
		ModelAndView mv=new ModelAndView("searchProductList.product","list",list);
		mv.addObject("info",name);
		mv.addObject("category",category);
		return mv;
	}
	
	@RequestMapping("/searchProductListByOrder.do")
	public ModelAndView searchProductListByOrder(String name, String category, String order){
		List<ProductVO> list=productService.searchProductListByOrder(name,category,order);		
		ModelAndView mv=new ModelAndView("searchProductList.product","list",list);
		mv.addObject("info",name);
		mv.addObject("category",category);
		return mv;
	}
	
	@RequestMapping("/getProductInfo.do")
	public ModelAndView getProductInfo(HttpSession session, String productId, String pageNo){
		ProductVO pvo=productService.getProductInfo(productId);
		ListVO lvo=reviewBoardService.getReviewBoardListPaging(pageNo,productId);
		HashMap map=new HashMap();
		map.put("info", pvo);
		map.put("lvo", lvo);
		return new ModelAndView("productInfo.product","map",map);
	}

	/*@RequestMapping("/searchProductListByMaker.do")
	public ModelAndView searchProductListByMaker(String maker, String category){
		List<ProductVO> list=productService.searchProductListByMaker(maker,category);
		
		return new ModelAndView("searchProductList.product","list",list);
	}
	
	@RequestMapping("/findProductListByPrice.do")
	public ModelAndView findProductListByPrice(int min,int max,String category){
		List<ProductVO> list=productService.findProductListByPrice(min,max,category);
		return new ModelAndView("searchProductList.product","list",list);
	}*/
}
